package com.zzw.hj101;

import java.util.Scanner;

/**
 * @Project: hw_java
 * @Description: 输入整型数组和排序标识，对其元素按照升序或降序排序
 * @Author: zzw
 */

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n];
        int flag;
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        flag = in.nextInt();
        for (int i = 0; i < n - 1; i++) {
            for (int j = 0; j < n - i - 1; j++) {
                if ((flag == 0) && (arr[j] > arr[j + 1])) {
                    int temp = arr[j + 1];
                    arr[j + 1] = arr[j];
                    arr[j] = temp;
                } else if ((flag == 1) && ((arr[j] < arr[j + 1]))) {
                    int temp = arr[j + 1];
                    arr[j + 1] = arr[j];
                    arr[j] = temp;
                }
            }
        }
        for (int i : arr) {
            System.out.print(i + " ");
        }
    }
}
